{[{define "sys/auth/add.html"}]}
{[{template "sys/base/mark.html"}]}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增页面</title>
    <link rel="stylesheet" href="/pear-admin-layui/component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" action="">
    <input name="pid" type="hidden" value="{[{.pid}]}">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">name</label>
                <div class="layui-input-block">
                    <input type="text" name="name" autocomplete="off" placeholder="name"
                           lay-verType="tips" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">url</label>
                <div class="layui-input-block">
                    <input type="text" name="url" autocomplete="off" placeholder="url" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">code</label>
                <div class="layui-input-block">
                    <input type="text" name="code" autocomplete="off" placeholder="code" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">type</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required" lay-verType="tips">
                        {[{ range $i, $v := .authTypes }]}
                        <option value="{[{ $v.DataValue }]}"
                                {[{if $v.IsDefault}]}
                                selected
                                {[{end}]}
                        >{[{ $v.DataLabel }]}
                        </option>
                        {[{ end }]}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">sort</label>
                <div class="layui-input-block">
                    <input type="number" name="sort" autocomplete="off" placeholder="sort"
                           lay-verType="tips" lay-verify="required" value="0" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">enable</label>
                <div class="layui-input-block">
                    <input type="checkbox" checked name="enable" lay-skin="switch">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">icon</label>
                <div class="layui-input-block">
                    <input type="text" id="iconPicker" name="icon" autocomplete="off" placeholder="icon"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">remark</label>
                <div class="layui-input-block">
                    <textarea name="remark" placeholder="remark" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="/pear-admin-layui/component/layui/layui.js"></script>
<script src="/pear-admin-layui/component/pear/pear.js"></script>
<script>

    layui.use(['form', 'jquery', 'loading', 'layer', 'iconPicker'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let loading = layui.loading;
        let layer = layui.layer;
        let iconPicker = layui.iconPicker;

        iconPicker.render({
            elem: '#iconPicker',
            type: 'fontClass',
            search: true,
            page: true,
            limit: 16,
            click: function (data) {
                console.log(data);
            },
            success: function (d) {
                console.log(d);
            }
        });

        form.on('submit(save)', function (data) {
            if (data.field.enable) {
                data.field.enable = true;
            }
            loading.Load(1, "loading data ...");
            $.post('/sys/auth/save', data.field, function (r) {
                loading.loadRemove(1000);
                if (r.code === 200) {
                    layer.msg(r.msg, {icon: 1, time: 1000}, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layui.treetable.reload("#power-table", {});
                    });
                } else {
                    layer.msg(r.msg, {icon: 2, time: 3000});
                }
            });
            return false;
        });
    })
</script>
</body>
</html>
{[{end}]}
